package com.manager.config.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manager.config.mapper.AgentMapper;
import com.manager.config.service.AgentService;


import com.manager.model.model.Agent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author pooh
* @description 针对表【agent】的数据库操作Service实现
* @createDate 2023-03-19 12:45:43
*/
@Service
public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent>
    implements AgentService {

    @Autowired
    AgentMapper agentMapper;
    @Override
    public boolean addAgent(String content) {
        Agent agent = agentMapper.searchByName(content);
        if(agent == null){
            Agent agent1 = new Agent();
            agent1.setName(content);
            agent1.setStatus(1);
            this.save(agent1);
        }else{
            if(agent.getStatus() == 0){
                agent.setStatus(1);
                this.updateById(agent);
            }else{
                return false;
            }
        }
        return true;
    }
}




